<template>
	<view class="home-container">
		<!-- 顶部搜索栏 -->
		<view class="search-bar">
			<view class="search-input">
				<text class="iconfont search-icon">🔍</text>
				<input 
					type="text" 
					placeholder="记得找点啥" 
					placeholder-class="placeholder-style"
					v-model="searchText"
				/>
			</view>
			<text class="iconfont menu-icon">☰</text>
		</view>
		
		<!-- 功能导航 -->
		<view class="nav-grid">
			<view class="nav-item" v-for="(item, index) in navItems" :key="index" @click="handleNavClick(item)">
				<text class="nav-icon" :style="{ color: item.color }">{{item.icon}}</text>
				<text class="nav-text">{{item.text}}</text>
			</view>
		</view>
		
		<!-- 书单推荐 -->
		<view class="section">
			<view class="section-header">
				<text class="section-title">书单推荐</text>
				<text class="section-more" @click="showMore('书单推荐')">更多 ></text>
			</view>
			<image class="banner-image" src="/static/book-banner.jpg" mode="aspectFill"></image>
		</view>
		
		<!-- 热门分类 -->
		<view class="categories">
			<view class="category-item" v-for="(category, index) in categories" :key="index" @click="handleCategoryClick(category)">
				<image class="category-image" :src="category.image" mode="aspectFill"></image>
				<text class="category-title">{{category.title}}</text>
			</view>
		</view>
		
		<!-- 图书列表 -->
		<view class="book-list">
			<view class="book-item" v-for="(book, index) in books" :key="index" @click="handleBookClick(book)">
				<image class="book-cover" :src="book.cover" mode="aspectFill"></image>
				<view class="book-info">
					<text class="book-title">{{book.title}}</text>
					<view class="book-meta">
						<text class="book-author">{{book.author}}</text>
						<text class="book-publisher">{{book.publisher}}</text>
					</view>
					<view class="book-price">
						<text class="price">¥{{book.price}}</text>
						<text class="original-price" v-if="book.originalPrice">¥{{book.originalPrice}}</text>
					</view>
				</view>
				<text class="cart-btn">🛒</text>
			</view>
		</view>
		
		<!-- 底部导航栏 -->
		<view class="tab-bar">
			<view class="tab-item" v-for="(tab, index) in tabs" :key="index" @click="handleTabClick(tab)">
				<text class="tab-icon">{{tab.icon}}</text>
				<text class="tab-text">{{tab.text}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchText: '',
				navItems: [
					{ icon: '🎓', text: '教材精选', color: '#FF6B00' },
					{ icon: '📚', text: '文学小说', color: '#2196F3' },
					{ icon: '📈', text: '统计数据', color: '#4CAF50' },
					{ icon: '🎨', text: '艺术类', color: '#9C27B0' }
				],
				categories: [
					{ title: '明信片专区', image: '/static/category1.jpg' },
					{ title: '热读榜单', image: '/static/category2.jpg' }
				],
				books: [
					{
						title: '我们与恶的距离',
						author: '吕莹',
						publisher: '广东人民出版社',
						price: 16,
						originalPrice: 20,
						cover: '/static/book1.jpg'
					},
					{
						title: '人类大迁徙',
						author: '王小波',
						publisher: '广东人民出版社',
						price: 60,
						cover: '/static/book2.jpg'
					}
				],
				tabs: [
					{ icon: '🏛️', text: '主页' },
					{ icon: '📖', text: '卖书' },
					{ icon: '🛒', text: '购物车' },
					{ icon: '👤', text: '我的' }
				]
			}
		},
		methods: {
			handleNavClick(item) {
				uni.showToast({
					title: `点击了${item.text}`,
					icon: 'none'
				});
			},
			showMore(section) {
				uni.showToast({
					title: `查看${section}更多内容`,
					icon: 'none'
				});
			},
			handleCategoryClick(category) {
				uni.showToast({
					title: `进入${category.title}`,
					icon: 'none'
				});
			},
			handleBookClick(book) {
				uni.showToast({
					title: `查看《${book.title}》详情`,
					icon: 'none'
				});
			},
			handleTabClick(tab) {
				if (tab.text === '卖书') {
					uni.switchTab({
						url: '/pages/sell/sell'
					});
				} else if (tab.text === '我的') {
					uni.switchTab({
						url: '/pages/my/my'
					});
				} else if (tab.text === '购物车') {
					uni.switchTab({
						url: '/pages/cart/cart'
					});
				}
			}
		}
	}
</script>

<style>
	.home-container {
		min-height: 100vh;
		background-color: #F5F5F5;
		padding-bottom: 120rpx;
	}
	
	/* 搜索栏样式 */
	.search-bar {
		background-color: #FF6B00;
		padding: 20rpx 30rpx;
		display: flex;
		align-items: center;
		gap: 20rpx;
	}
	
	.search-input {
		flex: 1;
		height: 72rpx;
		background: #FFFFFF;
		border-radius: 36rpx;
		display: flex;
		align-items: center;
		padding: 0 30rpx;
	}
	
	.search-icon {
		font-size: 36rpx;
		color: #999999;
		margin-right: 10rpx;
	}
	
	.menu-icon {
		font-size: 48rpx;
		color: #FFFFFF;
	}
	
	.placeholder-style {
		color: #999999;
		font-size: 28rpx;
	}
	
	/* 导航网格样式 */
	.nav-grid {
		display: flex;
		justify-content: space-around;
		padding: 40rpx 20rpx;
		background: #FFFFFF;
		margin-bottom: 20rpx;
	}
	
	.nav-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 10rpx;
	}
	
	.nav-icon {
		font-size: 48rpx;
	}
	
	.nav-text {
		font-size: 24rpx;
		color: #333333;
	}
	
	/* 书单推荐样式 */
	.section {
		background: #FFFFFF;
		padding: 30rpx;
		margin-bottom: 20rpx;
	}
	
	.section-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;
	}
	
	.section-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
	}
	
	.section-more {
		font-size: 24rpx;
		color: #999999;
	}
	
	.banner-image {
		width: 100%;
		height: 300rpx;
		border-radius: 16rpx;
	}
	
	/* 分类样式 */
	.categories {
		display: flex;
		justify-content: space-between;
		padding: 20rpx 30rpx;
		background: #FFFFFF;
		margin-bottom: 20rpx;
	}
	
	.category-item {
		width: 48%;
		position: relative;
	}
	
	.category-image {
		width: 100%;
		height: 200rpx;
		border-radius: 16rpx;
	}
	
	.category-title {
		position: absolute;
		bottom: 20rpx;
		left: 20rpx;
		color: #FFFFFF;
		font-size: 28rpx;
		font-weight: bold;
	}
	
	/* 图书列表样式 */
	.book-list {
		background: #FFFFFF;
		padding: 30rpx;
	}
	
	.book-item {
		display: flex;
		padding: 20rpx 0;
		border-bottom: 1rpx solid #EEEEEE;
		position: relative;
	}
	
	.book-cover {
		width: 180rpx;
		height: 240rpx;
		border-radius: 8rpx;
		margin-right: 20rpx;
	}
	
	.book-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
	
	.book-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
	}
	
	.book-meta {
		font-size: 24rpx;
		color: #999999;
	}
	
	.book-author {
		margin-right: 20rpx;
	}
	
	.book-price {
		display: flex;
		align-items: center;
		gap: 10rpx;
	}
	
	.price {
		color: #FF6B00;
		font-size: 32rpx;
		font-weight: bold;
	}
	
	.original-price {
		color: #999999;
		font-size: 24rpx;
		text-decoration: line-through;
	}
	
	.cart-btn {
		position: absolute;
		right: 0;
		bottom: 20rpx;
		font-size: 40rpx;
	}
	
	/* 底部导航栏样式 */
	.tab-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 100rpx;
		background: #FFFFFF;
		display: flex;
		justify-content: space-around;
		align-items: center;
		border-top: 1rpx solid #EEEEEE;
	}
	
	.tab-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 6rpx;
	}
	
	.tab-icon {
		font-size: 40rpx;
	}
	
	.tab-text {
		font-size: 24rpx;
		color: #333333;
	}
</style> 